<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<title>公共信息添加</title>
	<%@ include file="/WEB-INF/common/kindetor.jsp"%>
    <%@include file="/WEB-INF/common/hplus-css.jsp"%>
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <form action="${path}/article/add" class="form-horizontal m-t" id="userForm" method="post">                       	
                            <div class="form-group">
                                <label class="col-sm-3 control-label">标题：</label>
                                <div class="col-sm-6">
                                     <input type="text" id="title" name="title"  class="form-control" required=""  >
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">所属类别：</label>
                                <div class="col-sm-6">
                                    <select class="form-control m-b" name="genreCode" id="genreCode">
                                    	 <option value="0">登录首页幻灯片</option>
                                        <option value="1">政策信息</option>
                                        <option value="2" >排爆状态</option>
                                         <option value="3" >首页轮播幻灯片</option>
                                         <option value="4" >封面大图</option>
                                         <option value="5">用户指南</option>
                                    </select>
                                   <!--  <input type="hidden" class="form-control" name="genreName" id="genreName"/> -->
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">摘要：</label>
                                <div class="col-sm-6">
                                    <input type="text" class="form-control" name="summary"  >
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">外部链接：</label>
                                <div class="col-sm-6">
                                  <input type="text" placeholder="请输入外部链接" name="url" class="form-control"/>
								</div>
                            </div>
                             <div class="form-group">
                                <label class="col-sm-3 control-label">来源：</label>
                                <div class="col-sm-6">
                                  <input type="text" placeholder="请输入来源" name="resource" class="form-control"/>
								</div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">封面图片：</label>
                                <!-- <div class="col-sm-6">
                                    <input type="file" class="form-control" name="coverImageUrl">
                                </div> -->
                                <div class="col-sm-6">
										<div class="input-group">
											<input id="filename" class="form-control" name="coverImageUrl" ><!-- required="" -->
											<input type="hidden" id="attachId"
												placeholder="文件上传" name="attachId" minlength="2"
												class="form-control"  aria-required="true"
												value=""><span class="input-group-btn"> <a
												id="selectfile" onClick="upload('attachId')"
												href="javascript:" class="btn btn-primary">选择文件</a></span>
										</div>
									</div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">状态：</label>
                                <div class="col-sm-6">
                                    <select class="form-control m-b"  name="status">
                                        <option value="1">发布</option>
                                        <option value="2" >草稿</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">内容：</label>
                                 <div class="col-sm-6">
									<textarea placeholder="公告信息内容" name="content" class="form-control" required="" style="height:350px;"></textarea>
                                  </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-3" style="text-align: center;">
                                    <button class="btn btn-primary" id="add-btn" type="button">发布</button>
                                    <button class="btn btn-primary" id="back-btn" type="button" style="background-color:#ed5565; border-color: #ed5565; color: #fff;">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <%@include file="/WEB-INF/common/hplus-js.jsp"%>
    <script src="${path}/assets/hplus/js/demo/form-validate-demo.js"></script>
    <script>
    
    var clz = null;//name属性的值
    function upload(data) {
        //iframe窗 workRange
        clz = data;
        var proAreaCode = $(".workRange").find("option:selected").text();
        index = layer.open({
            type: 2,
            content: '${path}/common/selectfile', //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
            area: ['800px', '500px'],
            title: ['文件上传页面', 'font-size:18px;']
        });
    }
    function testA(path, name) {
        layer.close(index);
        console.log(path)
        $("input[id='filename']").val(name);//jquery通过name属性获取html对象并赋值
        $("input[name='" + clz + "']").val(path);//jquery通过name属性获取html对象并赋值
        $('#persionImg').hide();
    }
    
        $(document).ready(function () {
        	// 在键盘按下并释放及提交后验证提交表单
            $("#userForm").validate({
                  rules: {
                	  title: "required",//项目名
                      idCard: {//身份证号
                      	required: true,
                      	isIdCard:true,
                      },
                      releaseArea: "required",
                      publishContent:"required",
                      releaseDate: {
                          required: true,
                      },
                      summary: "required",
                      url: "required",
                      resource: "required",
                      /* coverImageUrl: "required", */
                      content: "required",
                  },
                  messages: {
                	  title: "必填",
                      idCard: {
                      	required: "必填",
                      	isIdCard:"请输入有效的身份证号"
                      },
                      releaseArea: "必填",
                      publishContent:"必填",
                      releaseDate: {
                          required: "必填",
                      },
                      summary: "必填",
                      url: "必填",
                      resource: "必填",
                      coverImageUrl: "必填",
                      content: "必填",
                     
                  }, invalidHandler: function(form, validator) {
                      var errors = validator.numberOfInvalids();
                      if (errors) {                    
                          validator.errorList[0].element.focus();
                      }
                  } 
              }) 
        	/* $("#userForm").validate(); */
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
          
            $("#back-btn").on("click", function() {
    			location.href = '${path}/article/query';
    		});
            $("#add-btn").click(function() {
            	var valid = $("#userForm").valid();
            	var genreCode=$("#genreCode").val();
            	if (genreCode=="3"||genreCode=="4") {
					if ( $("input[id='filename']").val()==null|| $("input[id='filename']").val()=="") {
						alert("请上传图片!");
						return;
					}
				}
            	if(valid) {
            		$("#userForm").ajaxSubmit({
                        dataType: "json",
                        success: function (json) {
                            var code = json.code;
                            if(code == 0){
                            	layer.msg('添加成功', {icon: 1});
                                setTimeout(function(){
                                	window.parent.location.reload();
                                	parent.parent.layer.closeAll();
                                }, 1000);
                            }else{
                            	layer.msg(json.msg, {icon: 5,time:2000});
                            }
                        },
                        error:function(){
                        	layer.msg('添加发生错误', {icon: 5});
                        }
                    });
            	}else{
            		layer.msg("请填写完整信息！！！！", {
						icon : 5
					});
                }
            });
        });
        //------------------富文本输入框初始化开始-------------------------------
    	var editor1;
    	var genreOldVal = "";
    	
    	KindEditor.ready(function(K) {
    			editor1 = K.create('textarea[name="content"]', {
    			uploadJson : '${path }/servlet/uploadKindeditorServlet.html',
    			fileManagerJson : '${path }/servlet/fileManageKindeditorServlet.html',
    			allowFileManager : true,
    			afterCreate : function() { 
    				this.sync(); 
    			},afterBlur : function() {
    				this.sync();
    				K.ctrl(document, 13, function() {
    					K('form[name=dataForm]')[0].submit();
    				});
    				K.ctrl(this.edit.doc, 13, function() {
    					K('form[name=dataForm]')[0].submit();
    				});
    			}
    		});
    		prettyPrint();
    	});
    	
    </script>
</body>
</html>
